package resource.loaders
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import resource.event.LoadResEvent;
	

	/**
	 * 数据对象的载入
	 * @author quexi
	 */	
	public class TextLoader extends EventDispatcher implements IResLoader
	{
		private var _urlLoader:URLLoader;
		private var _url:String;
		private var _resId:String;
		
		public function TextLoader()
		{
			_urlLoader = new URLLoader();
		}
		
		public function load(url:String = ""):void
		{
			if(url != "")
				_url = url;
			_urlLoader.load(new URLRequest(_url));
			_urlLoader.addEventListener(Event.COMPLETE, completeHandler);
			_urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}
		
		public function getData():*
		{
			return _urlLoader.data;
		}
		
		private function completeHandler(e:Event):void
		{
			dispatchEvent(new LoadResEvent(LoadResEvent.LOAD_OK));
		}
		
		private function ioErrorHandler(e:IOErrorEvent):void
		{
			trace(e.toString());
		}

		public function get url():String
		{
			return _url;
		}

		public function set url(value:String):void
		{
			_url = value;
		}

		public function get resId():String
		{
			return _resId;
		}

		public function set resId(value:String):void
		{
			_resId = value;
		}

		//
	}
}